<template>
	<view class="template-ranking" :style="'background:' + bg[rand]">
		<!-- 流星-->
		<view class="tn-satr">
			<view class="sky"></view>
			<view class="stars">
				<view class="falling-stars">
					<view class="star-fall"></view>
					<view class="star-fall"></view>
					<view class="star-fall"></view>
					<view class="star-fall"></view>
				</view>
				<view class="small-stars">
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
				</view>
				<view class="medium-stars">
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
					<view class="star"></view>
				</view>
			</view>
		</view>

		<view class="top-backgroup">
			<image :src="system.domain+'/assets/addons/kzvote/img/rank.png'" mode="widthFix" class="backgroud-image"></image>
		</view>

		<view class="flex" v-if="person.length > 2">
			<view class="user-info__container" v-if="person[1]"
				@click="goto('/pages/vote/person?person_id=' + person[1].id)">
				<view class="user-info__avatar user-info__avatar-two">
					<u-image :src="imgUrl + person[1].image" width="140rpx" height="140rpx" shape="circle"></u-image>
				</view>
				<view style="width: 140rpx;margin-top: 10rpx;">
					<u-text :text="person[1].name" align="center" lines="2" color="#fff" :bold="true"></u-text>
				</view>
				<view style="width: 140rpx;margin-top: 10rpx;">
					<u-text :text="person[1].count + '票'" align="center" lines="1" color="#fff" :bold="true"></u-text>
				</view>
			</view>
			<view class="user-info__container" v-if="person[0]"
				@click="goto('/pages/vote/person?person_id=' + person[0].id)">
				<view class="user-info__avatar user-info__avatar-one">
					<u-image :src="imgUrl + person[0].image" width="180rpx" height="180rpx" shape="circle"></u-image>
				</view>
				<view style="width: 180rpx;margin-top: 10rpx;">
					<u-text :text="person[0].name" align="center" lines="2" color="#fff" :bold="true"></u-text>
				</view>
				<view style="width: 180rpx;margin-top: 10rpx;">
					<u-text :text="person[0].count + '票'" align="center" lines="1" color="#fff" :bold="true"></u-text>
				</view>
			</view>
			<view class="user-info__container" v-if="person[2]"
				@click="goto('/pages/vote/person?person_id=' + person[2].id)">
				<view class="user-info__avatar user-info__avatar-three">
					<u-image :src="imgUrl + person[2].image" width="120rpx" height="120rpx" shape="circle"></u-image>
				</view>
				<view style="width: 120rpx;margin-top: 10rpx;">
					<u-text :text="person[2].name" align="center" lines="2" color="#fff" :bold="true"></u-text>
				</view>
				<view style="width: 120rpx;margin-top: 10rpx;">
					<u-text :text="person[2].count + '票'" align="center" lines="1" color="#fff" :bold="true"></u-text>
				</view>
			</view>
			<view class="user-info__container" v-else></view>
		</view>

		<view class="person">
			<view class="nav_title--wrap" style="background-image: url(/static/img/rank_title.png);">
				<u-text text="投票活动实时排名" size="22" align="center" color="#e45656" :bold="true"></u-text>
			</view>
			<view class="common">
				<!-- #ifdef MP-WEIXIN -->
				<ad :unit-id="ad.vote_rank" v-if="ad.vote_rank" ad-intervals="30" style="margin-bottom: 10px;"></ad>
				<!-- #endif -->
				<u-grid :border="false" col="4" v-if="vote && vote.groups && vote.groups.length > 0">
					<u-grid-item @click="select_group(-1)"><text class="grid-text"
							:style="group_id == -1 ? 'color:#fff;background:' + bg[rand] : ''">全部</text></u-grid-item>
					<u-grid-item v-for="(item, index) in vote.groups" :key="index" @click="select_group(item.id)">
						<text class="grid-text"
							:style="group_id == item.id ? 'color:#fff;background:' + bg[rand] : ''">{{ item.name }}</text>
					</u-grid-item>
				</u-grid>
				<u-row customStyle="margin-bottom:15px" v-if="person.length > 0">
					<u-col span="1.5">
						<u-text text="排名" size="12" color="#7A848B"></u-text>
					</u-col>
					<u-col span="7.5">
						<u-text text="选手" size="12" color="#7A848B"></u-text>
					</u-col>
					<u-col span="3">
						<u-text text="票数" align="center" size="12" color="#7A848B"></u-text>
					</u-col>
				</u-row>
				<view class="persons">
					<u-row v-for="(item, index) in person" :key="index" customStyle="margin-bottom:15px"
						@click="goto('/pages/vote/person?person_id=' + item.id)">
						<u-col span="1.5">
							<u-text :text="index + 1" v-if="index > 2"></u-text>
							<view v-else>
								<u-image src="/static/img/rank1.png" width="45rpx" height="60rpx" v-if="index == 0">
								</u-image>
								<u-image src="/static/img/rank2.png" width="45rpx" height="60rpx" v-if="index == 1">
								</u-image>
								<u-image src="/static/img/rank3.png" width="45rpx" height="60rpx" v-if="index == 2">
								</u-image>
							</view>
						</u-col>
						<u-col span="7.5">
							<u-text :text="item.name" :prefixIcon="imgUrl + item.image" size="28rpx" color="#7A848B"
								lines="2" iconStyle="width:40px;height:40px;border-radius:50%;margin-right:20rpx;"
								:bold="true"></u-text>
						</u-col>
						<u-col span="3">
							<view :style="'border-radius:15px;background:' + bg[rand]">
								<u-text :text="item.count + ' 票'" align="center" size="14" color="#fff" lines="1"
									lineHeight="30"></u-text>
							</view>
						</u-col>
					</u-row>
					<u-loadmore :status="has_more == true ? 'loading' : 'nomore'" />
				</view>
			</view>
		</view>
		<tabbar :vote_id="vote_id" :temp_name="vote.temp_name" v-if="vote"></tabbar>

		<music :music="vote.music" v-if="vote"></music>
	</view>
</template>

<script>
	import music from '@/components/music/music.vue';
	import tabbar from '@/components/tabbar/vote-tabbar.vue';
	import {
		mapGetters
	} from 'vuex';
	export default {
		computed: {
			...mapGetters({
				imgUrl: 'common/cdnurl',
				system: 'common/system',
				ad: 'common/ad',
			})
		},
		components: {
			tabbar,
			music
		},
		data() {
			return {
				vote_id: 0,
				vote: null,
				page: 1,
				has_more: true,
				group_id: -1,
				person: [],
				rand: uni.$u.random(0, 4),
				bg: [
					'linear-gradient(-120deg, #5969f6, #0976ea, #01BEFF, #00F5D4)',
					'linear-gradient(-120deg, #F15BB5, #9A5CE5, #01BEFF, #00F5D4)',
					'linear-gradient(-120deg,  #9A5CE5, #01BEFF, #00F5D4, #43e97b)',
					'linear-gradient(-120deg,#c471f5, #ec008c, #ff4e50,#f9d423)',
					'linear-gradient(-120deg,#c471f5, #ec008c, #ff4e50,#f9d423)'
				]
			};
		},
		async onLoad(options) {
			await this.$onLaunched;
			this.vote_id = options.vote_id;
			this.http(
				'vote/detail', {
					vote_id: this.vote_id
				},
				'get'
			).then(res => {
				this.vote = res.data;
				if (this.vote.shield_status == 1){
					//屏蔽流量主
					this.$store.state.common.ad = null
				}else{
					// #ifdef MP-WEIXIN
					this.adUtils.cp.load('vote_rank_cp')
					// #endif
				}
				// #ifdef MP-WEIXIN
				uni.$u.mpShare = {
					title: this.vote.name,
					path: '/pages/vote/index?vote_id=' + this.vote.id,
					imageUrl: this.imgUrl + this.vote.image,
				}
				// #endif
				this.utils.share({
					title: this.vote.name,
					imgUrl: this.imgUrl + this.vote.image,
				})
			});
			this.persons();
		},
		onReachBottom() {
			if (this.has_more) {
				this.persons();
			}
		},
		methods: {
			persons() {
				var data = {};
				data.vote_id = this.vote_id;
				data.page = this.page;
				data.order = 'count';
				if (this.group_id > -1) {
					data.group_id = this.group_id;
				}
				this.http('person/index', data, 'get').then(res => {
					var data = res.data.data;
					this.person = this.person || [];
					this.person = this.person.concat(data);
					this.has_more = res.data.has_more;
					this.page++;
				});
			},
			select_group(group_id) {
				console.log(1111);
				console.log(group_id);
				this.group_id = group_id;
				this.person = null;
				this.page = 1;
				this.has_more = true;
				this.persons();
			},
			goto(url) {
				this.utils.goto(url);
			}
		}
	};
</script>
<style lang="scss" scoped>
	/* 背景*/
	.template-ranking {
		margin: 0;
		width: 100%;
		height: 100%;
		background-size: 500% 500%;
		animation: gradientBG 15s ease infinite;
	}

	@keyframes gradientBG {
		0% {
			background-position: 0% 50%;
		}

		50% {
			background-position: 100% 50%;
		}

		100% {
			background-position: 0% 50%;
		}
	}

	/* 顶部背景图 start */
	.top-backgroup {
		opacity: 0.8;
		height: 450rpx;
		z-index: -1;
		padding-top: 13vh;

		.backgroud-image {
			width: 100%;
			height: 450rpx;
			z-index: -1;
		}
	}

	/* 顶部背景图 end */

	/* 用户信息 start */
	.flex {
		display: -webkit-flex;
		display: flex;
		justify-content: space-around;
		position: absolute;
		z-index: 99999;
		width: 90%;
		left: 0;
		right: 0;
		margin: 0 auto;

		.user-info {
			&__container {
				margin-top: -16vh;
			}

			&__avatar {
				border: 8rpx solid rgba(255, 255, 255, 0.05);
				border-radius: 50%;
				overflow: hidden;
				box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
			}

			&__avatar-one {
				margin-top: -90rpx;
				width: 180rpx;
				height: 180rpx;
			}

			&__avatar-two {
				width: 140rpx;
				height: 140rpx;
			}

			&__avatar-three {
				margin-top: 60rpx;
				width: 120rpx;
				height: 120rpx;
			}
		}
	}

	/* 用户信息 end */

	/* 标题 start */
	.nav_title--wrap {
		position: relative;
		display: flex;
		height: 120rpx;
		align-items: center;
		justify-content: center;
		font-weight: bold;
		background-size: cover;
	}

	/* 标题 end */
	.person {
		background-color: rgba(255, 255, 255, 1);
		position: relative;
		border-radius: 50rpx 50rpx 0 0;
		margin-top: 14vh;
		padding: 20rpx 10rpx 100rpx 10rpx;

		.common {
			background-color: #fff;
			padding: 30rpx 30rpx 20rpx;

			.grid-text {
				height: 64rpx;
				line-height: 64rpx;
				padding: 0 26rpx;
				background-color: #fff;
				border-radius: 60rpx;
				color: #666666;
				margin-bottom: 10px;
				font-size: 12px;
				min-width: 50px;
				text-align: center;
			}
		}
	}

	/* 流星*/
	.tn-satr {
		position: fixed;
		width: 100%;
		height: 400px;
		overflow: hidden;
		flex-shrink: 0;
		z-index: 99;
	}

	.stars {
		position: absolute;
		z-index: 1;
		width: 100%;
		height: 400px;
	}

	.star {
		border-radius: 50%;
		background: #ffffff;
		box-shadow: 0px 0px 6px 0px rgba(255, 255, 255, 0.8);
	}

	.small-stars .star {
		position: absolute;
		width: 3px;
		height: 3px;
	}

	.small-stars .star:nth-child(2n) {
		opacity: 0;
		-webkit-animation: star-blink 1.2s linear infinite alternate;
		animation: star-blink 1.2s linear infinite alternate;
	}

	.small-stars .star:nth-child(1) {
		left: 40px;
		bottom: 50px;
	}

	.small-stars .star:nth-child(2) {
		left: 200px;
		bottom: 40px;
	}

	.small-stars .star:nth-child(3) {
		left: 60px;
		bottom: 120px;
	}

	.small-stars .star:nth-child(4) {
		left: 140px;
		bottom: 250px;
	}

	.small-stars .star:nth-child(5) {
		left: 400px;
		bottom: 300px;
	}

	.small-stars .star:nth-child(6) {
		left: 170px;
		bottom: 80px;
	}

	.small-stars .star:nth-child(7) {
		left: 200px;
		bottom: 360px;
		-webkit-animation-delay: 0.2s;
		animation-delay: 0.2s;
	}

	.small-stars .star:nth-child(8) {
		left: 250px;
		bottom: 320px;
	}

	.small-stars .star:nth-child(9) {
		left: 300px;
		bottom: 340px;
	}

	.small-stars .star:nth-child(10) {
		left: 130px;
		bottom: 320px;
		-webkit-animation-delay: 0.5s;
		animation-delay: 0.5s;
	}

	.small-stars .star:nth-child(11) {
		left: 230px;
		bottom: 330px;
		-webkit-animation-delay: 7s;
		animation-delay: 7s;
	}

	.small-stars .star:nth-child(12) {
		left: 300px;
		bottom: 360px;
		-webkit-animation-delay: 0.3s;
		animation-delay: 0.3s;
	}

	@-webkit-keyframes star-blink {
		50% {
			width: 3px;
			height: 3px;
			opacity: 1;
		}
	}

	@keyframes star-blink {
		50% {
			width: 3px;
			height: 3px;
			opacity: 1;
		}
	}

	.medium-stars .star {
		position: absolute;
		width: 3px;
		height: 3px;
		opacity: 0;
		-webkit-animation: star-blink 1.2s ease-in infinite alternate;
		animation: star-blink 1.2s ease-in infinite alternate;
	}

	.medium-stars .star:nth-child(1) {
		left: 300px;
		bottom: 50px;
	}

	.medium-stars .star:nth-child(2) {
		left: 400px;
		bottom: 40px;
		-webkit-animation-delay: 0.4s;
		animation-delay: 0.4s;
	}

	.medium-stars .star:nth-child(3) {
		left: 330px;
		bottom: 300px;
		-webkit-animation-delay: 0.2s;
		animation-delay: 0.2s;
	}

	.medium-stars .star:nth-child(4) {
		left: 460px;
		bottom: 300px;
		-webkit-animation-delay: 0.9s;
		animation-delay: 0.9s;
	}

	.medium-stars .star:nth-child(5) {
		left: 300px;
		bottom: 150px;
		-webkit-animation-delay: 1.2s;
		animation-delay: 1.2s;
	}

	.medium-stars .star:nth-child(6) {
		left: 440px;
		bottom: 120px;
		-webkit-animation-delay: 1s;
		animation-delay: 1s;
	}

	.medium-stars .star:nth-child(7) {
		left: 200px;
		bottom: 140px;
		-webkit-animation-delay: 0.8s;
		animation-delay: 0.8s;
	}

	.medium-stars .star:nth-child(8) {
		left: 30px;
		bottom: 480px;
		-webkit-animation-delay: 0.3s;
		animation-delay: 0.3s;
	}

	.medium-stars .star:nth-child(9) {
		left: 460px;
		bottom: 400px;
		-webkit-animation-delay: 1.2s;
		animation-delay: 1.2s;
	}

	.medium-stars .star:nth-child(10) {
		left: 150px;
		bottom: 10px;
		-webkit-animation-delay: 1s;
		animation-delay: 1s;
	}

	.medium-stars .star:nth-child(11) {
		left: 420px;
		bottom: 450px;
		-webkit-animation-delay: 1.2s;
		animation-delay: 1.2s;
	}

	.medium-stars .star:nth-child(12) {
		left: 340px;
		bottom: 180px;
		-webkit-animation-delay: 1.1s;
		animation-delay: 1.1s;
	}

	@keyframes star-blink {
		50% {
			width: 4px;
			height: 4px;
			opacity: 1;
		}
	}

	.star-fall {
		position: relative;
		border-radius: 2px;
		width: 80px;
		height: 2px;
		overflow: hidden;
		-webkit-transform: rotate(-20deg);
		transform: rotate(-20deg);
	}

	.star-fall:after {
		content: '';
		position: absolute;
		width: 50px;
		height: 2px;
		background: -webkit-gradient(linear, right top, left top, from(rgba(0, 0, 0, 0)), to(rgba(255, 255, 255, 0.4)));
		background: linear-gradient(to left, rgba(0, 0, 0, 0) 0%, rgba(255, 255, 255, 0.4) 100%);
		left: 100%;
		-webkit-animation: star-fall 3.6s linear infinite;
		animation: star-fall 3.6s linear infinite;
	}

	.star-fall:nth-child(1) {
		left: 80px;
		bottom: -100px;
	}

	.star-fall:nth-child(1):after {
		-webkit-animation-delay: 2.4s;
		animation-delay: 2.4s;
	}

	.star-fall:nth-child(2) {
		left: 200px;
		bottom: -200px;
	}

	.star-fall:nth-child(2):after {
		-webkit-animation-delay: 2s;
		animation-delay: 2s;
	}

	.star-fall:nth-child(3) {
		left: 430px;
		bottom: -50px;
	}

	.star-fall:nth-child(3):after {
		-webkit-animation-delay: 3.6s;
		animation-delay: 3.6s;
	}

	.star-fall:nth-child(4) {
		left: 400px;
		bottom: 100px;
	}

	.star-fall:nth-child(4):after {
		-webkit-animation-delay: 0.2s;
		animation-delay: 0.2s;
	}

	@-webkit-keyframes star-fall {
		20% {
			left: -100%;
		}

		100% {
			left: -100%;
		}
	}

	@keyframes star-fall {
		20% {
			left: -100%;
		}

		100% {
			left: -100%;
		}
	}
</style>
